﻿
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using gfLibrary;

using DBUtility;

using Model;
using BLL;

namespace GreatGF
{
    public partial class INSPECTION_DEV_REG_INFO_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                string strMode = Request["m"];

                if((strMode == "u")||(strMode == "b")||(strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    INSPECTION_DEV_REG_INFO_BLL m_INSPECTION_DEV_REG_INFO_BLL = new INSPECTION_DEV_REG_INFO_BLL();

                    if(m_INSPECTION_DEV_REG_INFO_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        INSPECTION_DEV_REG_INFO m_INSPECTION_DEV_REG_INFO = new INSPECTION_DEV_REG_INFO();
                        m_INSPECTION_DEV_REG_INFO = m_INSPECTION_DEV_REG_INFO_BLL.GetModel(Convert.ToInt32(strId));

                        txtID.Text = m_INSPECTION_DEV_REG_INFO.ID.ToString();
                        txtJCXH.Text = m_INSPECTION_DEV_REG_INFO.JCXH.ToString();
                        txtSBLX.Text = m_INSPECTION_DEV_REG_INFO.SBLX;
                        txtSBMC.Text = m_INSPECTION_DEV_REG_INFO.SBMC;
                        txtSBMCDH.Text = m_INSPECTION_DEV_REG_INFO.SBMCDH;
                        txtSBZZC.Text = m_INSPECTION_DEV_REG_INFO.SBZZC;
                        txtSBXH.Text = m_INSPECTION_DEV_REG_INFO.SBXH;
                        txtSBCCBH.Text = m_INSPECTION_DEV_REG_INFO.SBCCBH;
                        txtSBCCRQ.Text = m_INSPECTION_DEV_REG_INFO.SBCCRQ;
                        txtSBRZBH.Text = m_INSPECTION_DEV_REG_INFO.SBRZBH;
                        txtSBRZRQ.Text = m_INSPECTION_DEV_REG_INFO.SBRZRQ;
                        txtSBRZYXQZ.Text = m_INSPECTION_DEV_REG_INFO.SBRZYXQZ;
                        txtJLBDBH.Text = m_INSPECTION_DEV_REG_INFO.JLBDBH;
                        txtJLBDRQ.Text = m_INSPECTION_DEV_REG_INFO.JLBDRQ;
                        txtJLBDYXQZ.Text = m_INSPECTION_DEV_REG_INFO.JLBDYXQZ;
                        txtBZ.Text = m_INSPECTION_DEV_REG_INFO.BZ;
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "INSPECTION_DEV_REG_INFO_List.aspx");
                    }

                    if((strMode == "b")||(strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtJCXH.ReadOnly = true;
                        txtJCXH.CssClass = "csstextboxreadonly";
                        txtSBLX.ReadOnly = true;
                        txtSBLX.CssClass = "csstextboxreadonly";
                        txtSBMC.ReadOnly = true;
                        txtSBMC.CssClass = "csstextboxreadonly";
                        txtSBMCDH.ReadOnly = true;
                        txtSBMCDH.CssClass = "csstextboxreadonly";
                        txtSBZZC.ReadOnly = true;
                        txtSBZZC.CssClass = "csstextboxreadonly";
                        txtSBXH.ReadOnly = true;
                        txtSBXH.CssClass = "csstextboxreadonly";
                        txtSBCCBH.ReadOnly = true;
                        txtSBCCBH.CssClass = "csstextboxreadonly";
                        txtSBCCRQ.ReadOnly = true;
                        txtSBCCRQ.CssClass = "csstextboxreadonly";
                        txtSBRZBH.ReadOnly = true;
                        txtSBRZBH.CssClass = "csstextboxreadonly";
                        txtSBRZRQ.ReadOnly = true;
                        txtSBRZRQ.CssClass = "csstextboxreadonly";
                        txtSBRZYXQZ.ReadOnly = true;
                        txtSBRZYXQZ.CssClass = "csstextboxreadonly";
                        txtJLBDBH.ReadOnly = true;
                        txtJLBDBH.CssClass = "csstextboxreadonly";
                        txtJLBDRQ.ReadOnly = true;
                        txtJLBDRQ.CssClass = "csstextboxreadonly";
                        txtJLBDYXQZ.ReadOnly = true;
                        txtJLBDYXQZ.CssClass = "csstextboxreadonly";
                        txtBZ.ReadOnly = true;
                        txtBZ.CssClass = "csstextboxreadonly";
                        btnSave.Visible = false;
                    }

                    if(strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
                if (strMode == "i")
                {
                    lblOperateType.Text = "添加";
                }
                if (strMode == "b" || strMode == "r")
                {
                    lblOperateType.Text = "查看";
                }
                if (strMode == "u")
                {
                    lblOperateType.Text = "修改";
                }
            }

            btnBack.Attributes["onclick"] = "javascript:window.location.href='INSPECTION_DEV_REG_INFO_List.aspx';return false;";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strJCXH = txtJCXH.Text.Trim();
            string strSBLX = txtSBLX.Text.Trim();
            string strSBMC = txtSBMC.Text.Trim();
            string strSBMCDH = txtSBMCDH.Text.Trim();
            string strSBZZC = txtSBZZC.Text.Trim();
            string strSBXH = txtSBXH.Text.Trim();
            string strSBCCBH = txtSBCCBH.Text.Trim();
            string strSBCCRQ = txtSBCCRQ.Text.Trim();
            string strSBRZBH = txtSBRZBH.Text.Trim();
            string strSBRZRQ = txtSBRZRQ.Text.Trim();
            string strSBRZYXQZ = txtSBRZYXQZ.Text.Trim();
            string strJLBDBH = txtJLBDBH.Text.Trim();
            string strJLBDRQ = txtJLBDRQ.Text.Trim();
            string strJLBDYXQZ = txtJLBDYXQZ.Text.Trim();
            string strBZ = txtBZ.Text.Trim();

            if (gfValidate.Is_Integer(strJCXH) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[JCXH]不是有效的数字格式。");
                return;
            }

            INSPECTION_DEV_REG_INFO m_INSPECTION_DEV_REG_INFO = new INSPECTION_DEV_REG_INFO();
            INSPECTION_DEV_REG_INFO_BLL m_INSPECTION_DEV_REG_INFO_BLL = new INSPECTION_DEV_REG_INFO_BLL();

            m_INSPECTION_DEV_REG_INFO.JCXH = Convert.ToInt32(strJCXH);
            m_INSPECTION_DEV_REG_INFO.SBLX = strSBLX;
            m_INSPECTION_DEV_REG_INFO.SBMC = strSBMC;
            m_INSPECTION_DEV_REG_INFO.SBMCDH = strSBMCDH;
            m_INSPECTION_DEV_REG_INFO.SBZZC = strSBZZC;
            m_INSPECTION_DEV_REG_INFO.SBXH = strSBXH;
            m_INSPECTION_DEV_REG_INFO.SBCCBH = strSBCCBH;
            m_INSPECTION_DEV_REG_INFO.SBCCRQ = strSBCCRQ;
            m_INSPECTION_DEV_REG_INFO.SBRZBH = strSBRZBH;
            m_INSPECTION_DEV_REG_INFO.SBRZRQ = strSBRZRQ;
            m_INSPECTION_DEV_REG_INFO.SBRZYXQZ = strSBRZYXQZ;
            m_INSPECTION_DEV_REG_INFO.JLBDBH = strJLBDBH;
            m_INSPECTION_DEV_REG_INFO.JLBDRQ = strJLBDRQ;
            m_INSPECTION_DEV_REG_INFO.JLBDYXQZ = strJLBDYXQZ;
            m_INSPECTION_DEV_REG_INFO.BZ = strBZ;

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_INSPECTION_DEV_REG_INFO_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                //m_INSPECTION_DEV_REG_INFO.ID = m_INSPECTION_DEV_REG_INFO_BLL.GetMax_ID();

                if (m_INSPECTION_DEV_REG_INFO_BLL.Insert(m_INSPECTION_DEV_REG_INFO) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = m_INSPECTION_DEV_REG_INFO.ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_INSPECTION_DEV_REG_INFO_BLL.Update(m_INSPECTION_DEV_REG_INFO, Convert.ToInt32(strID)) == true)
                {
                     gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}
